home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1033 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  91 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: uszvnwgn@ibmmail.com (Harold Putman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: PLEASE PLEASE HELP HELP...question on interleaving C functions
  5. Date: Thu, 11 Jan 1996 00:45:43 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4d1c1r$rqa@dub-news-svc-2.compuserve.com>
  8. References: <1995Dec30.194449.16565@wvnvms>
  9. NNTP-Posting-Host: ad52-024.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. un025043@wvnvms.wvnet.edu wrote:
  13.  
  14. >The scenario...
  15.  
  16. >main()
  17. >{
  18.  
  19. >sub1(parameters);
  20. >sub2(parameters);
  21.  
  22. >}
  23.  
  24. >sub1(...)
  25. >{
  26. >..some statemenmts
  27. >}
  28.  
  29. >sub2(...)
  30. >{
  31. >..some statements
  32. >}
  33.  
  34. >I intend main to call sub1, such that sub1 executes ONLY 1 INSTRUCTION, &
  35. >returns control to main.
  36. >Main then calls sub2, which again executes a single instrcution & returns.
  37. >Main then calls sub1, which executes the next instruction ( only 1 again)
  38. >and returns to main.
  39. >Main thus calls sub1, sub2, sub1, sub2 alternately until both sub1 & sub2
  40. >run out of instructions.
  41.  
  42. try something like this
  43.  
  44. #define DONE 1
  45. #define NOT_DONE 0
  46. int sub1()
  47.   {
  48.   static int instruction = 1;
  49.   switch(instruction)
  50.     {
  51.      case 1:
  52.        [first instruction];
  53.        break;
  54.     case 2:
  55.        [second instruction];
  56.        break;
  57.     ...
  58.     deafult:
  59.       return DONE;
  60.     }
  61.  instruction++;
  62.  return NOT_DONE;
  63.  }
  64.  
  65. Sub2 would look just like sub1 but with different instructions. Your
  66. main could look like...
  67.  
  68. main()
  69.   {
  70.   do
  71.     {
  72.     done1 = sub1();
  73.     done2 = sub2();
  74.     } while(!done1 && !done2);
  75.   }
  76.  
  77. This ought to do the trick for you, but document carefully that the
  78. cases in sub1 and sub2 are always executed in order starting with case
  79. 1. I actually used something like this once. It does the job but it is
  80. sort a maintenance headache since it is not immediatley obvious what
  81. is going on.
  82.  
  83. Harold Putman              
  84. InterBold Dept. 9-52       /  IBMMAIL:    USZVNWGN
  85. 5995 Mayfair Rd.           /  Internet:   uszvnwgn@ibmmail.com
  86. North Canton, OH  44720    /  CompuServe: 73744,2632
  87. USA                        /  Tel: (216) 490-4723  FAX: (216) 490-4508
  88.  
  89.  
  90.  
  91.